#include <errno.h>
#include <string.h>

/*
#include "Base/lib/lib.common.h"
#include "Base/lib/lib.log.h"
#include "Base/lib/lib.conn.h"
*/



/* UserName should be less than 30
 * Passwd should be less than 20 */
BOOL getAuthed(int sockFD,const char *uname, const char *passwd){

	/* +17 because of counting
	 * the length of
	 *  `GETAUTH` `END`
	 * */
	char buffer[MAX_USER_NAME_LEN+MAX_PASSWD_LEN+17+1];
	int authRet;
	BOOL ret=TRUE;

	ASSERT(sockFD>0);
	ASSERT(name!=NULL);
	ASSERT(passwd!=NULL);

	logIt(LOG_INFO,"getAuthed: Start to authenticate user %s",uname);
	sprintf(buffer,"`GetAuth` %s %s `END`",uname,passwd);
	if(-1==write(sockFD,buffer,strlen(buffer+1))){
		logIt(LOG_ERROR,"Failed write GETAUTH %s. Error Message: %s",uname,strerror(errno));
		return FALSE;
	}

	if(-1==recvfrom(sockFD,buffer,MAX_USER_NAME_LEN+MAX_PASSWD_LEN+17+1,0)){
		logIt(LOG_ERROR,"Failed write GETAUTH %s. Error Message: %s",uname,strerror(errno));
		return FALSE;
	}

	sscanf(buffer,"`GETAUTH` %d `END`",&authRet);
	if(AUTH_SUCCESS!=authRet){
		logIt(LOG_ERROR,"Fail to authenticate user %s")
	}


	logIt(LOG_INFO,"getAuthed: Finish authenticating user %s",uname);
	return TRUE;

}
